'use strict';

const Controller = require('egg').Controller;
/**
* @controller DbaProfileController 注释必写，swagger-doc是根据这段注释来生成接口的 ）。
*/
class DbaProfileController extends Controller {
  async list() {
        /**
        * @summary dbaprofilelist
        * @description dbaprofilelist
        * @router get /dbaprofilelist
        * @request query String OltId
        * @request query String search
        */
    const params = this.ctx.query
    const result = await this.ctx.service.dbaProfile.list(params)
    this.ctx.body = {
        status:200,
        msg:"",
        data: result.rows,
        count: result.count
    }
  }
  async allList() {
     /**
        * @summary dbaprofilealllist
        * @description dbaprofilealllist
        * @router get /dbaprofilealllist
        * @request query String OltId
        */
    const params = this.ctx.query
    const result = await this.ctx.service.dbaProfile.allList(params)
    this.ctx.body = {
        status:200,
        msg:"",
        data: result,
    }
  }
  async create() {
    const params = this.ctx.request.body
    let oltResult = await this.ctx.model.Olt.findOne({_id:params.oltId})
    const result = await this.ctx.service.dbaProfile.create(params)
    global.log.desc = ` ${oltResult.name} ${oltResult.oltIP} `+result.msg
    this.ctx.body = {
      status:200,
      data:result
    }
  }
  async edit() {
    const params = this.ctx.request.body
    let oltResult = await this.ctx.model.Olt.findOne({_id:params.oltId})
    const result = await this.ctx.service.dbaProfile.edit(params)
    global.log.desc = ` ${oltResult.name} ${oltResult.oltIP} `+result.msg
    this.ctx.body = {
      status:200,
      data:result
    }
  }
  async delete() {
    const params = this.ctx.query
    let dbaProfileResult = await this.ctx.model.DbaProfile.findOne({_id:params.id})
    let oltResult = await this.ctx.model.Olt.findOne({_id:dbaProfileResult.oltId})
    const result = await this.ctx.service.dbaProfile.delete(params)
    global.log.desc = ` ${oltResult.name} ${oltResult.oltIP} `+result.msg
    this.ctx.body = {
      status:200,
      data:result
    }
  }
}

module.exports = DbaProfileController;
